Skip to content

Expose SNI (tls server name indication)#323

Merged
sunng87 merged 8 commits intosunng87:masterfrom
ybrs:expose-sni
Oct 10, 2025
Merged

Expose SNI (tls server name indication)#323
sunng87 merged 8 commits intosunng87:masterfrom
ybrs:expose-sni

Conversation

@ybrs
Copy link
Copy Markdown
Contributor

@ybrs ybrs commented Oct 9, 2025

We expose server_name from rustls to client metadata with this PR.

This is helpful in some cases. If one is using pgwire for loadbalancing/routing amongst servers, can decide with server_name. Also I think it can be helpful for some sanity checks, if one is trying to connect via scanning ip addresses etc. server can just close the connection as something is going fishy.

I tried to come up with some unit tests (tried a few ways, in the end this works in macos and linux but I'm open to suggestions )

Also tested manually. I have a branch that is checking this server_name in riffq, it works with simply when tls is enabled [1]

Simply connecting with when tls is enabled psql after version 12 sends the SNI.

psql "host=example.com port=5444"

In ssl=verify-full or ssl=require etc. it also works.

When tls is enabled but if client doesn't send sni it also sets server_name as None (or when connecting with ip)

 psql "host=example.com port=5444 sslmode=prefer sslsni=0"

Let me know what you think.

[1] ybrs/riffq#105

ybrs added 6 commits October 9, 2025 13:17
- After TLS accept, read rustls connection server_name and store it.
- Use metadata key  (aligns with rustls naming) instead of .
- Keep change minimal: update before framing, using mutable client_info.
- Add unit test to validate SNI extraction with localhost certificate.
- Stand up ad-hoc TLS server/client using repo demo cert.
- Mirror production logic: insert rustls server_name into DefaultClient metadata.
- Assert metadata[server_name] == "localhost".
- Use rustls dangerous() custom verifier to skip cert validation.
- Focus the test on SNI plumbing rather than PKI constraints.
- Provide required signature verification methods and Debug impl.
- Keeps the test focused on SNI observation.
@ybrs ybrs changed the title Expose sni (tls server name indication) Expose SNI (tls server name indication) Oct 9, 2025
Comment thread src/tokio/server.rs
@sunng87
Copy link
Copy Markdown
Owner

sunng87 commented Oct 9, 2025

@ybrs Thank you for the patch! This is reasonable. We already provide access to client certificate so it's important to provide sni server name too.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good

Copy link
Copy Markdown
Owner

@sunng87 sunng87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you @ybrs !

@sunng87 sunng87 merged commit 3f48022 into sunng87:master Oct 10, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants